package com.eii.resubmit.aop.request.annotation;

import org.springframework.core.annotation.AnnotationUtils;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

/**
 * 控制重复请求注解,只用于controller中的端点
 * @author eii
 * @sice 2020/11/28
 */
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface RepeatLock {

    public static class RepeatLockHelper {
        public static RepeatLock get(Method method, Class<?> targetClass){
            RepeatLock annotation = AnnotationUtils.findAnnotation(method, RepeatLock.class);
            /*if (annotation == null) {
                annotation = AnnotationUtils.findAnnotation(targetClass, RepeatLock.class);
                if (annotation != null) {
                    if (AnnotationUtils.findAnnotation(targetClass, TimeoutLock.class) != null) {
                        throw new IllegalStateException("不能在同一个类上同时放置TimeoutLock和RepeatLock注解");
                    }
                }
            } else {
                if (AnnotationUtils.findAnnotation(method, TimeoutLock.class) != null) {
                    throw new IllegalStateException("不能在同一个方法上同时放置TimeoutLock和RepeatLock注解");
                }
            }*/
            return annotation;
        }
    }
}
